<?php


namespace App\Http\Controllers;

use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

class MqController
{

    /** @var  AMQPStreamConnection*/
    public $connect = null;

    private $que = 'hello';


    public function conn()
    {
        $host = '192.168.3.203';
        $port = '5672';
        $user = 'MemberAdmin';
        $pwd = '123456';
        $this->connect = new AMQPStreamConnection($host, $port, $user, $pwd,'MemberHost');
    }

    public function index()
    {
        $this->conn();
       // exit();
        $channel = $this->connect->channel();
        $channel->queue_declare($this->que, false,false,false,false);
        $msg = 'Hello world';
        $msgObj = new AMQPMessage($msg);
        $channel->basic_publish($msgObj,'','hello');
        $channel->close();
        $this->connect->close();
        return '生产者完毕1';


    }
}
